+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
+2001-03-12 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: Switch to using an
+ enum with registration for icon sizes, instead of strings.
+
+ * gtkimage.h, gtkimage.c, gtkstyle.h, gtkstyle.c, gtkwidget.h,
+ gtkwidget.c: Fix to reflect GtkIconSize
+
2001-03-12 Alexander Larsson <alexl@redhat.com>
Make GtkFB compile and link.
@clist: The #GtkCList widget to check.
+<!-- ##### MACRO GTK_ICON_SIZE_BUTTON ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO GTK_ICON_SIZE_DIALOG ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO GTK_ICON_SIZE_LARGE_TOOLBAR ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO GTK_ICON_SIZE_MENU ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO GTK_ICON_SIZE_SMALL_TOOLBAR ##### -->
+<para>
+
+</para>
+
+
<!-- ##### MACRO GTK_OBJECT_CONSTRUCTED ##### -->
<para>
Test whether a GtkObject's arguments have been prepared.
</para>
+<!-- ##### USER_FUNCTION GtkEmissionHook ##### -->
+<para>
+A simple function pointer to get invoked when the
+signal is emitted. This allows you tie a hook to the signal type,
+so that it will trap all emissions of that signal, from any object.
+</para>
+<para>
+You may not attach these to signals created with the
+#GTK_RUN_NO_HOOKS flag.
+</para>
+
+@object:
+@signal_id:
+@n_params:
+@params:
+@data:
+@Returns:
+
<!-- ##### ENUM GtkFontFilterType ##### -->
<para>
A set of bit flags used to specify the filter being set
@ruler: the gtkruler
+<!-- ##### FUNCTION gtk_signal_add_emission_hook ##### -->
+<para>
+Add an emission hook for a type of signal, for any object.
+</para>
+
+@signal_id: the type of signal to hook for.
+@hook_func: the function to invoke to handle the emission hook.
+@data: the user data passed in to hook_func.
+@Returns: the id (that you may pass as a parameter
+to gtk_signal_remove_emission_hook()).
+@i:
+@h:
+@d:
+
<!-- ##### FUNCTION gtk_signal_add_emission_hook_full ##### -->
<para>
Add an emission hook for a type of signal, for any object.
@object: the object whose signal handlers should be destroyed.
+<!-- ##### FUNCTION gtk_signal_init ##### -->
+<para>
+
+</para>
+
+
<!-- ##### FUNCTION gtk_signal_n_emissions ##### -->
<para>
Find out the recursion depth of emissions for a particular type
which contains all the information, or NULL.
The pointer is allocated just for you: you must g_free() it.
+<!-- ##### FUNCTION gtk_signal_remove_emission_hook ##### -->
+<para>
+Delete an emission hook. (see gtk_signal_add_emission_hook())
+</para>
+
+@signal_id: the id of the signal type.
+@hook_id: the id of the emission handler, returned by add_emission_hook().
+@i:
+@h:
+
<!-- ##### FUNCTION gtk_signal_set_funcs ##### -->
<para>
These set default functions to call when the user didn't
@icon_set:
-<!-- ##### MACRO GTK_ICON_SIZE_MENU ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### MACRO GTK_ICON_SIZE_BUTTON ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### MACRO GTK_ICON_SIZE_SMALL_TOOLBAR ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### MACRO GTK_ICON_SIZE_LARGE_TOOLBAR ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### MACRO GTK_ICON_SIZE_DIALOG ##### -->
-<para>
-
-</para>
-
-
-
<!-- ##### FUNCTION gtk_icon_size_lookup ##### -->
<para>
</para>
-@alias:
+@size:
@width:
@height:
@Returns:
+<!-- # Unused Parameters # -->
+@alias:
<!-- ##### FUNCTION gtk_icon_size_register ##### -->
</para>
-@alias:
+@name:
@width:
@height:
+@Returns:
+<!-- # Unused Parameters # -->
+@alias:
<!-- ##### FUNCTION gtk_icon_size_register_alias ##### -->
@field:
-<!-- ##### USER_FUNCTION GtkEmissionHook ##### -->
-<para>
-A simple function pointer to get invoked when the
-signal is emitted. This allows you tie a hook to the signal type,
-so that it will trap all emissions of that signal, from any object.
-</para>
-<para>
-You may not attach these to signals created with the
-#GTK_RUN_NO_HOOKS flag.
-</para>
-
-@object:
-@signal_id:
-@n_params:
-@params:
-@data:
-@Returns:
-
-
<!-- ##### ENUM GtkSignalRunType ##### -->
<para>
These configure the signal's emission. They control
@GTK_RUN_ACTION:
@GTK_RUN_NO_HOOKS:
-<!-- ##### FUNCTION gtk_signal_init ##### -->
-<para>
-
-</para>
-
-
-
<!-- ##### FUNCTION gtk_signal_new ##### -->
<para>
Create a new signal type. (This is usually done in the
the callbacks.
-<!-- ##### FUNCTION gtk_signal_lookup ##### -->
+<!-- ##### MACRO gtk_signal_lookup ##### -->
<para>
Given the name of the signal and the type of object it connects
to, get the signal's identifying integer. Emitting the signal
It also tries the ancestors of the given type.
</para>
+@Returns: the signal's identifying number, or 0 if no signal was found.
+<!-- # Unused Parameters # -->
@name: the signal's name, e.g. clicked.
@object_type: the type that the signal operates on, e.g. #GTK_TYPE_BUTTON.
-@Returns: the signal's identifying number, or 0 if no signal was found.
-<!-- ##### FUNCTION gtk_signal_name ##### -->
+<!-- ##### MACRO gtk_signal_name ##### -->
<para>
Given the signal's identifier, find its name.
</para>
Two different signals may have the same name, if they have differing types.
</para>
-@signal_id: the signal's identifying number.
@Returns: the signal name, or NULL if the signal number was invalid.
+<!-- # Unused Parameters # -->
+@signal_id: the signal's identifying number.
<!-- ##### FUNCTION gtk_signal_emit ##### -->
followed by one which is a pointer to the return type.
-<!-- ##### FUNCTION gtk_signal_emit_stop ##### -->
+<!-- ##### MACRO gtk_signal_emit_stop ##### -->
<para>
This function aborts a signal's current emission.
</para>
isn't being emitted.
</para>
-@object: the object whose signal handlers you wish to stop.
-@signal_id: the signal identifier, as returned by gtk_signal_lookup().
-<!-- # Unused Parameters # -->
@i:
@s:
+<!-- # Unused Parameters # -->
+@object: the object whose signal handlers you wish to stop.
+@signal_id: the signal identifier, as returned by gtk_signal_lookup().
<!-- ##### FUNCTION gtk_signal_emit_stop_by_name ##### -->
@name: the name of the signal you wish to stop.
-<!-- ##### FUNCTION gtk_signal_connect ##### -->
+<!-- ##### MACRO gtk_signal_connect ##### -->
<para>
Attach a function pointer and user data to a signal for
a particular object.
</programlisting>
</informalexample>
+@o:
+@s:
+@f:
+@d:
+@Returns: the connection id.
+<!-- # Unused Parameters # -->
@object: the object associated with the signal, e.g. if a button
is getting pressed, this is that button.
@name: name of the signal.
@func: function pointer to attach to the signal.
@func_data: value to pass as to your function (through the marshaller).
-@Returns: the connection id.
-<!-- # Unused Parameters # -->
-@o:
-@s:
-@f:
-@d:
-<!-- ##### FUNCTION gtk_signal_connect_after ##### -->
+<!-- ##### MACRO gtk_signal_connect_after ##### -->
<para>
Attach a function pointer and user data to a signal
so that this handler will be called after the other handlers.
</para>
-@object: the object associated with the signal.
-@name: name of the signal.
-@func: function pointer to attach to the signal.
-@func_data: value to pass as to your function (through the marshaller).
-@Returns: the unique identifier for this attachment: the connection id.
-<!-- # Unused Parameters # -->
@o:
@s:
@f:
@d:
+@Returns: the unique identifier for this attachment: the connection id.
+<!-- # Unused Parameters # -->
+@object: the object associated with the signal.
+@name: name of the signal.
+@func: function pointer to attach to the signal.
+@func_data: value to pass as to your function (through the marshaller).
-<!-- ##### FUNCTION gtk_signal_connect_object ##### -->
+<!-- ##### MACRO gtk_signal_connect_object ##### -->
<para>
This function is for registering a callback that will
call another object's callback. That is,
</programlisting>
</informalexample>
+@o:
+@s:
+@f:
+@d:
+@Returns: the connection id.
+<!-- # Unused Parameters # -->
@object: the object which emits the signal.
@name: the name of the signal.
@func: the function to callback.
@slot_object: the object to pass as the first parameter to func.
(Though it pretends to take an object, you can
really pass any gpointer as the #slot_object .)
-@Returns: the connection id.
-<!-- # Unused Parameters # -->
-@o:
-@s:
-@f:
-@d:
-<!-- ##### FUNCTION gtk_signal_connect_object_after ##### -->
+<!-- ##### MACRO gtk_signal_connect_object_after ##### -->
<para>
Attach a signal hook to a signal, passing in an alternate
object as the first parameter, and guaranteeing
handlers are called first.
</para>
-@object: the object associated with the signal.
-@name: name of the signal.
-@func: function pointer to attach to the signal.
-@slot_object: the object to pass as the first parameter to #func.
-@Returns: the connection id.
-<!-- # Unused Parameters # -->
@o:
@s:
@f:
@d:
+@Returns: the connection id.
+<!-- # Unused Parameters # -->
+@object: the object associated with the signal.
+@name: name of the signal.
+@func: function pointer to attach to the signal.
+@slot_object: the object to pass as the first parameter to #func.
<!-- ##### FUNCTION gtk_signal_connect_full ##### -->
@name: name of the signal.
-<!-- ##### FUNCTION gtk_signal_disconnect ##### -->
+<!-- ##### MACRO gtk_signal_disconnect ##### -->
<para>
Destroy a user-defined handler connection.
</para>
+<!-- # Unused Parameters # -->
@object: the object which the handler pertains to.
@handler_id: the connection id.
-<!-- ##### FUNCTION gtk_signal_disconnect_by_func ##### -->
+<!-- ##### MACRO gtk_signal_disconnect_by_func ##### -->
<para>
Destroy all connections for a particular object, with
the given function-pointer and user-data.
</para>
-@object: the object which emits the signal.
-@func: the function pointer to search for.
-@data: the user data to search for.
-<!-- # Unused Parameters # -->
@o:
@f:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal.
+@func: the function pointer to search for.
+@data: the user data to search for.
-<!-- ##### FUNCTION gtk_signal_disconnect_by_data ##### -->
+<!-- ##### MACRO gtk_signal_disconnect_by_data ##### -->
<para>
Destroy all connections for a particular object, with
the given user-data.
</para>
-@object: the object which emits the signal.
-@data: the user data to search for.
-<!-- # Unused Parameters # -->
@o:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal.
+@data: the user data to search for.
-<!-- ##### FUNCTION gtk_signal_handler_block ##### -->
+<!-- ##### MACRO gtk_signal_handler_block ##### -->
<para>
Prevent an user-defined handler from being invoked. All other
signal processing will go on as normal, but this particular
handler will ignore it.
</para>
+<!-- # Unused Parameters # -->
@object: the object which emits the signal to block.
@handler_id: the connection id.
-<!-- ##### FUNCTION gtk_signal_handler_block_by_func ##### -->
+<!-- ##### MACRO gtk_signal_handler_block_by_func ##### -->
<para>
Prevent a user-defined handler from being invoked, by reference to
the user-defined handler's function pointer and user data. (It may result in
multiple hooks being blocked, if you've called connect multiple times.)
</para>
-@object: the object which emits the signal to block.
-@func: the function pointer of the handler to block.
-@data: the user data of the handler to block.
-<!-- # Unused Parameters # -->
@o:
@f:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal to block.
+@func: the function pointer of the handler to block.
+@data: the user data of the handler to block.
-<!-- ##### FUNCTION gtk_signal_handler_block_by_data ##### -->
+<!-- ##### MACRO gtk_signal_handler_block_by_data ##### -->
<para>
Prevent all user-defined handlers with a certain user data from being invoked.
</para>
-@object: the object which emits the signal we want to block.
-@data: the user data of the handlers to block.
-<!-- # Unused Parameters # -->
@o:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal we want to block.
+@data: the user data of the handlers to block.
-<!-- ##### FUNCTION gtk_signal_handler_unblock ##### -->
+<!-- ##### MACRO gtk_signal_handler_unblock ##### -->
<para>
Undo a block, by connection id. Note that undoing a block doesn't
necessarily make the hook callable, because if you block a
hook twice, you must unblock it twice.
</para>
+<!-- # Unused Parameters # -->
@object: the object which emits the signal we want to unblock.
@handler_id: the emission handler identifier, as returned by
gtk_signal_connect(), etc.
-<!-- ##### FUNCTION gtk_signal_handler_unblock_by_func ##### -->
+<!-- ##### MACRO gtk_signal_handler_unblock_by_func ##### -->
<para>
Undo a block, by function pointer and data.
Note that undoing a block doesn't
hook twice, you must unblock it twice.
</para>
-@object: the object which emits the signal we want to unblock.
-@func: the function pointer to search for.
-@data: the user data to search for.
-<!-- # Unused Parameters # -->
@o:
@f:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal we want to unblock.
+@func: the function pointer to search for.
+@data: the user data to search for.
-<!-- ##### FUNCTION gtk_signal_handler_unblock_by_data ##### -->
+<!-- ##### MACRO gtk_signal_handler_unblock_by_data ##### -->
<para>
Undo block(s), to all signals for a particular object
with a particular user-data pointer
</para>
-@object: the object which emits the signal we want to unblock.
-@data: the user data to search for.
-<!-- # Unused Parameters # -->
@o:
@d:
+<!-- # Unused Parameters # -->
+@object: the object which emits the signal we want to unblock.
+@data: the user data to search for.
-<!-- ##### FUNCTION gtk_signal_handler_pending ##### -->
+<!-- ##### MACRO gtk_signal_handler_pending ##### -->
<para>
Returns a connection id corresponding to a given signal id and object.
</para>
thus saving the cost of building the arguments.
</para>
+@i:
+@s:
+@b:
+@Returns: the connection id, if a connection was found. 0 otherwise.
+<!-- # Unused Parameters # -->
@object: the object to search for the desired user-defined handler.
@signal_id: the number of the signal to search for.
@may_be_blocked: whether it is acceptable to return a blocked
handler.
-@Returns: the connection id, if a connection was found. 0 otherwise.
-<!-- # Unused Parameters # -->
-@i:
-@s:
-@b:
-<!-- ##### FUNCTION gtk_signal_handler_pending_by_func ##### -->
+<!-- ##### MACRO gtk_signal_handler_pending_by_func ##### -->
<para>
Returns a connection id corresponding to a given signal id, object, function
pointer and user data.
</para>
-@object: the object to search for the desired handler.
-@signal_id: the number of the signal to search for.
-@may_be_blocked: whether it is acceptable to return a blocked
-handler.
-@func: the function pointer to search for.
-@data: the user data to search for.
-@Returns: the connection id, if a handler was found. 0 otherwise.
-<!-- # Unused Parameters # -->
@o:
@s:
@b:
@f:
@d:
-
-
-<!-- ##### FUNCTION gtk_signal_add_emission_hook ##### -->
-<para>
-Add an emission hook for a type of signal, for any object.
-</para>
-
-@signal_id: the type of signal to hook for.
-@hook_func: the function to invoke to handle the emission hook.
-@data: the user data passed in to hook_func.
-@Returns: the id (that you may pass as a parameter
-to gtk_signal_remove_emission_hook()).
-<!-- # Unused Parameters # -->
-@i:
-@h:
-@d:
-
-
-<!-- ##### FUNCTION gtk_signal_remove_emission_hook ##### -->
-<para>
-Delete an emission hook. (see gtk_signal_add_emission_hook())
-</para>
-
-@signal_id: the id of the signal type.
-@hook_id: the id of the emission handler, returned by add_emission_hook().
+@Returns: the connection id, if a handler was found. 0 otherwise.
<!-- # Unused Parameters # -->
-@i:
-@h:
+@object: the object to search for the desired handler.
+@signal_id: the number of the signal to search for.
+@may_be_blocked: whether it is acceptable to return a blocked
+handler.
+@func: the function pointer to search for.
+@data: the user data to search for.
<!-- ##### MACRO gtk_signal_default_marshaller ##### -->
@type_info: must not be null, and @type_info->type_name must also not be null.
-<!-- ##### FUNCTION gtk_type_name ##### -->
+<!-- ##### MACRO gtk_type_name ##### -->
<para>
</para>
-@type: a GtkType
@Returns: a pointer to the name of a type, or NULL if it has none.
+<!-- # Unused Parameters # -->
+@type: a GtkType
-<!-- ##### FUNCTION gtk_type_from_name ##### -->
+<!-- ##### MACRO gtk_type_from_name ##### -->
<para>
Get the internal representation of a type given its name.
</para>
-@name: the name of a gtk type
@Returns: a GtkType
+<!-- # Unused Parameters # -->
+@name: the name of a gtk type
-<!-- ##### FUNCTION gtk_type_parent ##### -->
+<!-- ##### MACRO gtk_type_parent ##### -->
<para>
</para>
-@type: a GtkType
@Returns: the GtkType of the parent
+<!-- # Unused Parameters # -->
+@type: a GtkType
<!-- ##### FUNCTION gtk_type_class ##### -->
@Returns: gpointer to a GtkTypeObject
-<!-- ##### FUNCTION gtk_type_is_a ##### -->
+<!-- ##### MACRO gtk_type_is_a ##### -->
<para>
Look in the type hierarchy to see if @type has @is_a_type among its
ancestors. Do so with a simple lookup, not a loop.
</para>
+@Returns:
+<!-- # Unused Parameters # -->
@type: GtkType
@is_a_type: GtkType
-@Returns:
<!-- ##### FUNCTION gtk_type_enum_get_values ##### -->
GTK_DIR_RIGHT
} GtkDirectionType;
+/* Built-in stock icon sizes */
+typedef enum
+{
+ GTK_ICON_SIZE_INVALID,
+ GTK_ICON_SIZE_MENU,
+ GTK_ICON_SIZE_SMALL_TOOLBAR,
+ GTK_ICON_SIZE_LARGE_TOOLBAR,
+ GTK_ICON_SIZE_BUTTON,
+ GTK_ICON_SIZE_DIALOG
+} GtkIconSize;
+
/* Reading directions for text */
typedef enum
{
static GtkIconSet *
sized_icon_set_from_inline (const guchar *inline_data,
- const gchar *size)
+ GtkIconSize size)
{
GtkIconSet *set;
- GtkIconSource source = { NULL, NULL, 0, 0, NULL,
+ GtkIconSource source = { NULL, NULL, 0, 0, 0,
TRUE, TRUE, FALSE };
- source.size = (gchar*) size;
+ source.size = size;
set = gtk_icon_set_new ();
static void
add_sized (GtkIconFactory *factory,
const guchar *inline_data,
- const gchar *size,
+ GtkIconSize size,
const gchar *stock_id)
{
GtkIconSet *set;
/* Sizes */
-static GHashTable *icon_sizes = NULL;
-
typedef struct _IconSize IconSize;
struct _IconSize
{
+ gint size;
gchar *name;
- gboolean is_alias;
-
- union
- {
- gchar *target;
- struct
- {
- gint width;
- gint height;
- } size;
- } d;
+ gint width;
+ gint height;
};
-static IconSize*
-icon_size_new (const gchar *name)
-{
- IconSize *is;
-
- is = g_new0 (IconSize, 1);
+typedef struct _IconAlias IconAlias;
- is->name = g_strdup (name);
-
- return is;
-}
-
-static void
-icon_size_free (IconSize *is)
+struct _IconAlias
{
- g_free (is->name);
-
- if (is->is_alias)
- g_free (is->d.target);
+ gchar *name;
+ gint target;
+};
- g_free (is);
-}
+static GHashTable *icon_aliases = NULL;
+static IconSize *icon_sizes = NULL;
+static gint icon_sizes_allocated = 0;
+static gint icon_sizes_used = 0;
static void
-icon_size_insert (IconSize *is)
-{
- gpointer old_key, old_value;
-
- /* Remove old ones */
- if (g_hash_table_lookup_extended (icon_sizes,
- is->name,
- &old_key, &old_value))
- {
- g_hash_table_remove (icon_sizes, is->name);
- icon_size_free (old_value);
- }
-
- g_hash_table_insert (icon_sizes,
- is->name, is);
-
-}
-
-static IconSize*
-icon_size_lookup (const gchar *name)
+init_icon_sizes (void)
{
- IconSize *is;
-
- is = g_hash_table_lookup (icon_sizes,
- name);
-
- while (is && is->is_alias)
+ if (icon_sizes == NULL)
{
- is = g_hash_table_lookup (icon_sizes,
- is->d.target);
-
- }
+#define NUM_BUILTIN_SIZES 6
+ gint i;
- return is;
-}
-
-static void
-icon_size_add (const gchar *name,
- gint width,
- gint height)
-{
- IconSize *is;
-
- is = icon_size_new (name);
- is->d.size.width = width;
- is->d.size.height = height;
-
- icon_size_insert (is);
-}
-
-static void
-icon_alias_add (const gchar *name,
- const gchar *target)
-{
- IconSize *is;
-
- is = icon_size_new (name);
- is->is_alias = TRUE;
-
- is->d.target = g_strdup (target);
+ icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
+
+ icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
+ icon_sizes_allocated = NUM_BUILTIN_SIZES;
+ icon_sizes_used = NUM_BUILTIN_SIZES;
+
+ icon_sizes[GTK_ICON_SIZE_INVALID].size = 0;
+ icon_sizes[GTK_ICON_SIZE_INVALID].name = NULL;
+ icon_sizes[GTK_ICON_SIZE_INVALID].width = 0;
+ icon_sizes[GTK_ICON_SIZE_INVALID].height = 0;
+
+ /* the name strings aren't copied since we don't ever remove
+ * icon sizes, so we don't need to know whether they're static.
+ * Even if we did I suppose removing the builtin sizes would be
+ * disallowed.
+ */
+
+ icon_sizes[GTK_ICON_SIZE_MENU].size = GTK_ICON_SIZE_MENU;
+ icon_sizes[GTK_ICON_SIZE_MENU].name = "gtk-menu";
+ icon_sizes[GTK_ICON_SIZE_MENU].width = 16;
+ icon_sizes[GTK_ICON_SIZE_MENU].height = 16;
+
+ icon_sizes[GTK_ICON_SIZE_BUTTON].size = GTK_ICON_SIZE_BUTTON;
+ icon_sizes[GTK_ICON_SIZE_BUTTON].name = "gtk-button";
+ icon_sizes[GTK_ICON_SIZE_BUTTON].width = 24;
+ icon_sizes[GTK_ICON_SIZE_BUTTON].height = 24;
+
+ icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].size = GTK_ICON_SIZE_SMALL_TOOLBAR;
+ icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
+ icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].width = 18;
+ icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].height = 18;
+
+ icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+ icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
+ icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
+ icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].height = 24;
- icon_size_insert (is);
-}
+ icon_sizes[GTK_ICON_SIZE_DIALOG].size = GTK_ICON_SIZE_DIALOG;
+ icon_sizes[GTK_ICON_SIZE_DIALOG].name = "gtk-dialog";
+ icon_sizes[GTK_ICON_SIZE_DIALOG].width = 48;
+ icon_sizes[GTK_ICON_SIZE_DIALOG].height = 48;
-static void
-init_icon_sizes (void)
-{
- if (icon_sizes == NULL)
- {
- icon_sizes = g_hash_table_new (g_str_hash, g_str_equal);
+ g_assert ((GTK_ICON_SIZE_DIALOG + 1) == NUM_BUILTIN_SIZES);
- icon_size_add (GTK_ICON_SIZE_MENU, 16, 16);
- icon_size_add (GTK_ICON_SIZE_BUTTON, 24, 24);
- icon_size_add (GTK_ICON_SIZE_SMALL_TOOLBAR, 18, 18);
- icon_size_add (GTK_ICON_SIZE_LARGE_TOOLBAR, 24, 24);
- icon_size_add (GTK_ICON_SIZE_DIALOG, 48, 48);
+ /* Alias everything to itself. */
+ i = 1; /* skip invalid size */
+ while (i < NUM_BUILTIN_SIZES)
+ {
+ gtk_icon_size_register_alias (icon_sizes[i].name, icon_sizes[i].size);
+
+ ++i;
+ }
+
+#undef NUM_BUILTIN_SIZES
}
}
/**
* gtk_icon_size_lookup:
- * @alias: name of an icon size
+ * @size: an icon size
* @width: location to store icon width
* @height: location to store icon height
*
- * Obtains the pixel size of an icon, normally @alias would be
+ * Obtains the pixel size of a semantic icon size, normally @size would be
* #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
* isn't normally needed, gtk_widget_render_icon() is the usual
* way to get an icon for rendering, then just look at the size of
* the rendered pixbuf. The rendered pixbuf may not even correspond to
* the width/height returned by gtk_icon_size_lookup(), because themes
- * are free to render the pixbuf however they like.
+ * are free to render the pixbuf however they like, including changing
+ * the usual size.
*
- * Return value: %TRUE if @alias was known.
+ * Return value: %TRUE if @size was a valid size
**/
gboolean
-gtk_icon_size_lookup (const gchar *alias,
+gtk_icon_size_lookup (GtkIconSize size,
gint *widthp,
gint *heightp)
{
- IconSize *is;
-
- g_return_val_if_fail (alias != NULL, FALSE);
-
init_icon_sizes ();
-
- is = icon_size_lookup (alias);
- if (is == NULL)
+ if (size >= icon_sizes_used)
return FALSE;
+ if (size == GTK_ICON_SIZE_INVALID)
+ return FALSE;
+
if (widthp)
- *widthp = is->d.size.width;
+ *widthp = icon_sizes[size].width;
if (heightp)
- *heightp = is->d.size.height;
+ *heightp = icon_sizes[size].height;
return TRUE;
}
/**
* gtk_icon_size_register:
- * @alias: name of the icon size
+ * @name: name of the icon size
* @width: the icon width
* @height: the icon height
*
* Registers a new icon size, along the same lines as #GTK_ICON_SIZE_MENU,
- * etc.
+ * etc. Returns the integer value for the size.
+ *
+ * Returns: integer value representing the size
*
**/
-void
-gtk_icon_size_register (const gchar *alias,
+GtkIconSize
+gtk_icon_size_register (const gchar *name,
gint width,
gint height)
{
- g_return_if_fail (alias != NULL);
- g_return_if_fail (width > 0);
- g_return_if_fail (height > 0);
+ g_return_val_if_fail (name != NULL, 0);
+ g_return_val_if_fail (width > 0, 0);
+ g_return_val_if_fail (height > 0, 0);
init_icon_sizes ();
- icon_size_add (alias, width, height);
+ if (icon_sizes_used == icon_sizes_allocated)
+ {
+ icon_sizes_allocated *= 2;
+ icon_sizes = g_renew (IconSize, icon_sizes, icon_sizes_allocated);
+ }
+
+ icon_sizes[icon_sizes_used].size = icon_sizes_used;
+ icon_sizes[icon_sizes_used].name = g_strdup (name);
+ icon_sizes[icon_sizes_used].width = width;
+ icon_sizes[icon_sizes_used].height = height;
+
+ /* alias to self. */
+ gtk_icon_size_register_alias (icon_sizes[icon_sizes_used].name,
+ icon_sizes[icon_sizes_used].size);
+
+ ++icon_sizes_used;
+
+ return icon_sizes_used - 1;
}
/**
* gtk_icon_size_register_alias:
* @alias: an alias for @target
- * @target: an existing icon size name
+ * @target: an existing icon size
+ *
+ * Registers @alias as another name for @target.
+ * So calling gtk_icon_size_from_name() with @alias as argument
+ * will return @target.
*
- * Registers @alias as another name for @target, usable when calling
- * gtk_icon_size_lookup().
- *
**/
void
gtk_icon_size_register_alias (const gchar *alias,
- const gchar *target)
+ GtkIconSize target)
{
+ IconAlias *ia;
+
g_return_if_fail (alias != NULL);
- g_return_if_fail (target != NULL);
init_icon_sizes ();
- icon_alias_add (alias, target);
+ if (g_hash_table_lookup (icon_aliases, alias))
+ g_warning ("gtk_icon_size_register_alias: Icon size name '%s' already exists", alias);
+
+ if (!gtk_icon_size_lookup (target, NULL, NULL))
+ g_warning ("gtk_icon_size_register_alias: Icon size %d does not exist", target);
+
+ ia = g_new (IconAlias, 1);
+ ia->name = g_strdup (alias);
+ ia->target = target;
+
+ g_hash_table_insert (icon_aliases, ia->name, ia);
+}
+
+GtkIconSize
+gtk_icon_size_from_name (const gchar *name)
+{
+ IconAlias *ia;
+
+ init_icon_sizes ();
+
+ ia = g_hash_table_lookup (icon_aliases, name);
+
+ if (ia)
+ return ia->target;
+ else
+ return GTK_ICON_SIZE_INVALID;
+}
+
+G_CONST_RETURN gchar*
+gtk_icon_size_get_name (GtkIconSize size)
+{
+ if (size >= icon_sizes_used)
+ return NULL;
+ else
+ return icon_sizes[size].name;
}
/* Icon Set */
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size);
+ GtkIconSize size);
static void add_to_cache (GtkIconSet *icon_set,
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GdkPixbuf *pixbuf);
static void clear_cache (GtkIconSet *icon_set,
gboolean style_detach);
{
GtkIconSet *set;
- GtkIconSource source = { NULL, NULL, 0, 0, NULL,
+ GtkIconSource source = { NULL, NULL, 0, 0, 0,
TRUE, TRUE, TRUE };
g_return_val_if_fail (pixbuf != NULL, NULL);
static gboolean
-sizes_equivalent (const gchar *rhs, const gchar *lhs)
+sizes_equivalent (GtkIconSize lhs,
+ GtkIconSize rhs)
{
gint r_w, r_h, l_w, l_h;
find_and_prep_icon_source (GtkIconSet *icon_set,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size)
+ GtkIconSize size)
{
GtkIconSource *source;
GSList *tmp_list;
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GtkWidget *widget,
const char *detail)
{
*copy = *source;
copy->filename = g_strdup (source->filename);
- copy->size = g_strdup (source->size);
+ copy->size = source->size;
if (copy->pixbuf)
g_object_ref (G_OBJECT (copy->pixbuf));
g_return_if_fail (source != NULL);
g_free ((char*) source->filename);
- g_free ((char*) source->size);
if (source->pixbuf)
g_object_unref (G_OBJECT (source->pixbuf));
GtkStyle *style;
GtkTextDirection direction;
GtkStateType state;
- gchar *size;
+ GtkIconSize size;
GdkPixbuf *pixbuf;
};
static void
cached_icon_free (CachedIcon *icon)
{
- g_free (icon->size);
g_object_unref (G_OBJECT (icon->pixbuf));
g_free (icon);
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size)
+ GtkIconSize size)
{
GSList *tmp_list;
GSList *prev;
if (icon->style == style &&
icon->direction == direction &&
icon->state == state &&
- strcmp (icon->size, size) == 0)
+ icon->size == size)
{
if (prev)
{
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GdkPixbuf *pixbuf)
{
CachedIcon *icon;
icon->style = style;
icon->direction = direction;
icon->state = state;
- icon->size = g_strdup (size);
+ icon->size = size;
icon->pixbuf = pixbuf;
if (icon->style)
g_object_ref (G_OBJECT (icon_copy->pixbuf));
- icon_copy->size = g_strdup (icon->size);
+ icon_copy->size = icon->size;
copy = g_slist_prepend (copy, icon_copy);
* size from the rendered pixbuf, not from here.
*/
-gboolean gtk_icon_size_lookup (const gchar *alias,
- gint *width,
- gint *height);
-void gtk_icon_size_register (const gchar *alias,
- gint width,
- gint height);
-void gtk_icon_size_register_alias (const gchar *alias,
- const gchar *target);
-
-
-/* Standard sizes */
-
-#define GTK_ICON_SIZE_MENU "gtk-menu"
-#define GTK_ICON_SIZE_SMALL_TOOLBAR "gtk-small-toolbar"
-#define GTK_ICON_SIZE_LARGE_TOOLBAR "gtk-large-toolbar"
-#define GTK_ICON_SIZE_BUTTON "gtk-button"
-#define GTK_ICON_SIZE_DIALOG "gtk-dialog"
+gboolean gtk_icon_size_lookup (GtkIconSize size,
+ gint *width,
+ gint *height);
+GtkIconSize gtk_icon_size_register (const gchar *name,
+ gint width,
+ gint height);
+void gtk_icon_size_register_alias (const gchar *alias,
+ GtkIconSize target);
+GtkIconSize gtk_icon_size_from_name (const gchar *name);
+G_CONST_RETURN gchar* gtk_icon_size_get_name (GtkIconSize size);
/* Icon sets */
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GtkWidget *widget,
const char *detail);
GtkTextDirection direction;
GtkStateType state;
- gchar *size;
+ GtkIconSize size;
/* If TRUE, then the parameter is wildcarded, and the above
* fields should be ignored. If FALSE, the parameter is
**/
GtkWidget*
gtk_image_new_from_stock (const gchar *stock_id,
- const gchar *size)
+ GtkIconSize size)
{
GtkImage *image;
**/
GtkWidget*
gtk_image_new_from_icon_set (GtkIconSet *icon_set,
- const gchar *size)
+ GtkIconSize size)
{
GtkImage *image;
void
gtk_image_set_from_stock (GtkImage *image,
const gchar *stock_id,
- const gchar *size)
+ GtkIconSize size)
{
g_return_if_fail (GTK_IS_IMAGE (image));
image->storage_type = GTK_IMAGE_STOCK;
image->data.stock.stock_id = g_strdup (stock_id);
- image->data.stock.size = g_strdup (size);
+ image->data.stock.size = size;
/* Size is demand-computed in size request method
* if we're a stock image, since changing the
void
gtk_image_set_from_icon_set (GtkImage *image,
GtkIconSet *icon_set,
- const gchar *size)
+ GtkIconSize size)
{
g_return_if_fail (GTK_IS_IMAGE (image));
image->storage_type = GTK_IMAGE_ICON_SET;
image->data.icon_set.icon_set = icon_set;
- image->data.icon_set.size = g_strdup (size);
+ image->data.icon_set.size = size;
/* Size is demand-computed in size request method
* if we're an icon set
* Gets the stock icon name and size being displayed by the #GtkImage.
* The storage type of the image must be %GTK_IMAGE_EMPTY or
* %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
- * The returned strings are owned by the #GtkImage and should not
+ * The returned string is owned by the #GtkImage and should not
* be freed.
*
**/
void
gtk_image_get_stock (GtkImage *image,
gchar **stock_id,
- gchar **size)
+ GtkIconSize *size)
{
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
* Gets the icon set and size being displayed by the #GtkImage.
* The storage type of the image must be %GTK_IMAGE_EMPTY or
* %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
- * The returned size string is owned by the #GtkImage and should not
- * be freed.
*
**/
void
gtk_image_get_icon_set (GtkImage *image,
GtkIconSet **icon_set,
- gchar **size)
+ GtkIconSize *size)
{
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
case GTK_IMAGE_STOCK:
- g_free (image->data.stock.size);
g_free (image->data.stock.stock_id);
image->data.stock.stock_id = NULL;
- image->data.stock.size = NULL;
+ image->data.stock.size = 0;
break;
if (image->data.icon_set.icon_set)
gtk_icon_set_unref (image->data.icon_set.icon_set);
- g_free (image->data.icon_set.size);
-
- image->data.icon_set.size = NULL;
+ image->data.icon_set.size = 0;
image->data.icon_set.icon_set = NULL;
break;
struct _GtkImageStockData
{
gchar *stock_id;
- gchar *size;
+ GtkIconSize size;
};
struct _GtkImageIconSetData
{
GtkIconSet *icon_set;
- gchar *size;
+ GtkIconSize size;
};
typedef enum
GtkWidget* gtk_image_new_from_file (const gchar *filename);
GtkWidget* gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf);
GtkWidget* gtk_image_new_from_stock (const gchar *stock_id,
- const gchar *size);
+ GtkIconSize size);
GtkWidget* gtk_image_new_from_icon_set (GtkIconSet *icon_set,
- const gchar *size);
+ GtkIconSize size);
void gtk_image_set_from_pixmap (GtkImage *image,
GdkPixmap *pixmap,
GdkPixbuf *pixbuf);
void gtk_image_set_from_stock (GtkImage *image,
const gchar *stock_id,
- const gchar *size);
+ GtkIconSize size);
void gtk_image_set_from_icon_set (GtkImage *image,
GtkIconSet *icon_set,
- const gchar *size);
+ GtkIconSize size);
GtkImageType gtk_image_get_storage_type (GtkImage *image);
GdkPixbuf* gtk_image_get_pixbuf (GtkImage *image);
void gtk_image_get_stock (GtkImage *image,
gchar **stock_id,
- gchar **size);
+ GtkIconSize *size);
void gtk_image_get_icon_set (GtkImage *image,
GtkIconSet **icon_set,
- gchar **size);
+ GtkIconSize *size);
#ifndef GTK_DISABLE_DEPRECATED
cleanup_source (GtkIconSource *source)
{
g_free (source->filename);
- g_free (source->size);
}
static guint
if (token != '*')
{
+ GtkIconSize size;
+
if (token != G_TOKEN_STRING)
{
cleanup_source (&source);
return G_TOKEN_STRING;
}
-
- source.size = g_strdup (scanner->value.v_string);
- source.any_size = FALSE;
+
+ size = gtk_icon_size_from_name (scanner->value.v_string);
+
+ if (size != GTK_ICON_SIZE_INVALID)
+ {
+ source.size = size;
+ source.any_size = FALSE;
+ }
}
/* Check the close brace */
const GtkIconSource *source,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GtkWidget *widget,
const gchar *detail);
const GtkIconSource *source,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GtkWidget *widget,
const gchar *detail)
{
static GdkPixbuf *
gtk_default_render_icon (GtkStyle *style,
- const GtkIconSource *source,
- GtkTextDirection direction,
- GtkStateType state,
- const gchar *size,
- GtkWidget *widget,
- const gchar *detail)
+ const GtkIconSource *source,
+ GtkTextDirection direction,
+ GtkStateType state,
+ GtkIconSize size,
+ GtkWidget *widget,
+ const gchar *detail)
{
gint width = 1;
gint height = 1;
const GtkIconSource *source,
GtkTextDirection direction,
GtkStateType state,
- const gchar *size,
+ GtkIconSize size,
GtkWidget *widget,
const gchar *detail);
const GtkIconSource *source,
GtkTextDirection direction,
GtkStateType state,
- const gchar * size,
+ GtkIconSize size,
GtkWidget *widget,
const gchar *detail);
void gtk_draw_hline (GtkStyle *style,
* identifies the widget or code doing the rendering, so that
* theme engines can special-case rendering for that widget or code.
*
- * Return value: a new pixbuf, or NULL if the stock ID wasn't known
+ * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
**/
GdkPixbuf*
gtk_widget_render_icon (GtkWidget *widget,
const gchar *stock_id,
- const gchar *size,
+ GtkIconSize size,
const gchar *detail)
{
GtkIconSet *icon_set;
GdkPixbuf *gtk_widget_render_icon (GtkWidget *widget,
const gchar *stock_id,
- const gchar *size,
+ GtkIconSize size,
const gchar *detail);
/* handle composite names for GTK_COMPOSITE_CHILD widgets,